﻿/**
 *    Copyright 2006 - 2011 Opera Software ASA
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 **/


/**
  * @constructor 
  */

var TopUIBase = function()
{ 
  this.changeStyleProperty = function(property, delta)
  {
    var 
    sheets = document.styleSheets, 
    sheet = null, 
    i = 0, 
    rules = null, 
    rule = null,
    cur_val = 0,
    is_set = false;


    // assumnig that border and padding are set just once

    for( ; ( sheet = sheets[i] ) && !is_set; i++)
    {
      rules = sheet.cssRules;
      for( i = 0; ( rule = rules[i] ) && !is_set; i++)
      {
        if( rule.type == 1 && rule.selectorText == this.type )
        {
          cur_val = parseInt(rule.style.getPropertyValue('padding-right'));
          
          if( cur_val || cur_val == 0 )
          {
            cur_val += delta;
            rule.style.setProperty(property, cur_val + 'px', '');
            this.constructor.prototype.style[property] = cur_val;
            this.setCSSProperties();
            this.setDimensions();
            if( this.render )
            {
              this.render();
            }
            is_set = true;
          }
        }
      }
    }
  }
}

